/**
*      author: Y_Yao
*      created: 2025-03-27 11:38:01
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 9e18;
const int INF = 0x3f3f3f3f;
const int N = 1e3 + 7;
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};
int n,m,k;
char a[N][N];
int sz[N * N];
int vis[N][N];

void dfs(int i,int j,int cnt)
{
    vis[i][j] = cnt;
    for(int k = 0;k < 4;k++)
    {
        int x = i + dx[k],y = j + dy[k];
        if(a[x][y] == '.' && !vis[x][y])
        {
            dfs(x,y,cnt);
        }
        else if(a[x][y] == '*')
        {
            sz[cnt]++;
        }
    }   
}

void solve()
{
    cin >> n >> m >> k;
    int cnt = 1;
    for(int i = 1;i <= n;i++)
    {
        for(int j = 1;j <= m;j++)
        {
            cin >> a[i][j];
        }
    }
    for(int i = 1;i <= n;i++)
    {
        for(int j = 1;j <= m;j++)
        {
            if(a[i][j] == '.' && !vis[i][j])
            {
                dfs(i,j,cnt);
                cnt++;
            }
        }
    }
    while(k--)
    {
        int x,y;
        cin >> x >> y;
        cout << sz[vis[x][y]] << endl;
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    // cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}